/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 adventure_path.h

	$Header: /heroes4/adventure_path.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( ADVENTURE_PATH_H_INCLUDED )
#define ADVENTURE_PATH_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#pragma warning( disable: 4786 )

#include <vector>
#include <streambuf>

#include "adv_map_point.h"
#include "direction.h"

class t_creature_array;

enum t_army_path_state
{
	k_army_path_state_normal = 0,
	k_army_path_state_water_walking,
	k_army_path_state_ship,

	k_army_path_state_count,

	// Special values only for use as arguments to the public version of t_adventure_path_finder::push()
	k_army_path_state_previous, // Use the previous point's value
	k_army_path_state_as_needed // Use normal if the tile is land, ship if the tile is water
};

// ---------------------------------------------------------------
// information needed about a point on the map during pathfinding
// ---------------------------------------------------------------
struct t_adventure_path_data
{
	unsigned int			visited						: 1;  // if there's any way to reach this cell.
	t_direction				direction				    : 5;
	unsigned int            blocked_by_enemy		    : 1;  // Applies to type k_path_search_caravan ONLY
															  // To reach this point, we went through a
															  // hostile enemy & have already be charged
															  // for going through
	unsigned int			touched						: 1; 

	unsigned int			actual_enemy_adjacent		: 1;
	t_direction				actual_enemy_direction		: 5;
	unsigned int			actual_enemy_distance		: 5;
	unsigned int			actual_restricts_movement	: 1;
	unsigned int			in_danger					: 1;
	unsigned int			visible_enemy_adjacent		: 1;
	t_direction				visible_enemy_direction		: 5;
	unsigned int			visible_enemy_distance		: 5;
	unsigned int			visible_restricts_movement	: 1;


	unsigned int			adjusted_move_cost;
	float					barrier_value;	
	t_creature_array const*	current_barrier;
	float					danger_value;
	t_adv_map_point			last_point;				// previous point in path.
	unsigned int			move_cost;				// cost in movement points to this point.
	unsigned int			move_remaining;
	t_army_path_state		pathing_state;
	t_uint16				step_count;
	float					value;

};

// ---------------------------------------------------------------
// class to store information about a single point in a path
// ---------------------------------------------------------------
struct t_adventure_path_point : public t_adventure_path_data, public t_adv_map_point
{
	t_adventure_path_point();
	explicit t_adventure_path_point( t_adv_map_point const& arg );
	t_adventure_path_point( t_adv_map_point const& point, t_adventure_path_data const& data );

	virtual bool read( std::streambuf & buffer );
	virtual bool write( std::streambuf & buffer ) const;
};

inline t_adventure_path_point::t_adventure_path_point()
{
}

inline t_adventure_path_point::t_adventure_path_point( t_adv_map_point const& arg )
                             : t_adv_map_point( arg )
{
}


inline t_adventure_path_point::t_adventure_path_point( t_adv_map_point const& point, 
													   t_adventure_path_data const& data )
						     : t_adv_map_point( point ), t_adventure_path_data( data )
{
}

// ---------------------------------------------------------------
// class to store a completed path
// ---------------------------------------------------------------
class t_adventure_path : public std::vector<t_adventure_path_point>
{
public:
	virtual bool read( std::streambuf& buffer );
	virtual bool read( std::streambuf& buffer, int version );
	virtual bool write( std::streambuf& buffer ) const;
};

#endif // ADVENTURE_PATH_H_INCLUDED